/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */

package org.jaxson.struts.encoder;


/**
 * Enum containing supported rendering contexts for struts actions. Maps content
 * type header strings and encoder classes to each supported rendering context.
 * 
 * @see org.jaxson.struts.encoder.ResponseEncoder
 * 
 * @author Joe Maisel
 */
public enum ResponseContentType
{
	jpg("image/jpeg", JpegEncoder.class), 
	xml("text/xml", XmlEncoder.class), 
	json("application/json", JsonEncoder.class), 
	//pdf("application/pdf", PdfEncoder.class), 
	csv("application/csv", CsvEncoder.class),
	excel("application/xls", ExcelEncoder.class),
	html("text/html", null);

	private String mimeType;
	private Class<ResponseEncoder> encoder;

	@SuppressWarnings("unchecked")
	private ResponseContentType (String mimeType, Class encoder)
	{
		this.mimeType = mimeType;
		this.encoder = encoder;
	}

	/**
	 * Get the mime type for the "Content-Type" http header.
	 */
	public String getMimeType()
	{
		return this.mimeType;
	}

	/**
	 * Get the encoder for a given content type.
	 * 
	 * @return
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 */
	public ResponseEncoder getEncoder() throws InstantiationException, IllegalAccessException
	{
		return encoder == null ? null : encoder.newInstance();
	}
}